<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
    	$question = M('question'); // 实例化question表的对象
		$count = $question->count();// 查询总记录数
		$Page = new \Think\Page($count,3);// 实例化分页类 传入总记录数和每页显示的记录数(3)
		$show = $Page->show();// 分页显示输出
    	$sql='select t1.*,t2.nikename,t2.face,t3.cname from question t1 inner join user t2 on t1.uid=t2.id inner join category t3 on t1.cid=t3.id order by t1.create_time desc limit '.$Page->firstRow.",".$Page->listRows;
    	$res=M()->query($sql);
    	$this->assign('res',$res);
		$this->assign('page',$show);// 赋值分页输出

		$user_sql="select face,nikename,answer_num,id from user  order by answer_num desc limit 6";
		$mongood=M()->query($user_sql);
		$this->assign('mongood',$mongood);//月度雷锋

		$hot_card_sql="select title,view_num,id from question order by view_num desc limit 10";
		$hotcard_res=M()->query($hot_card_sql);
		$this->assign('hotcard',$hotcard_res); //最近热帖

		$hot_answer_sql="select title,answer_num,id from question order by answer_num desc limit 10";
		$hotanswer_res=M()->query($hot_answer_sql);
		$this->assign('hotanswer',$hotanswer_res); //最近热议







        $this->display();		//引入html的函数
    }

    

    //未结帖
    public function noget(){
    	$question = M('question'); // 实例化question表的对象
		$count = $question->count();// 查询总记录数
		$Page = new \Think\Page($count,3);// 实例化分页类 传入总记录数和每页显示的记录数(3)
		$show = $Page->show();// 分页显示输出
    	$sql="select t1.*,t2.nikename,t2.id,t2.face,t3.cname from question t1 inner join user t2 on t1.uid=t2.id inner join category t3 on t1.cid=t3.id where t1.status='未结贴' order by t1.create_time desc limit ".$Page->firstRow.",".$Page->listRows;

    	$res=M()->query($sql);
    	$this->assign('res',$res);
    	$this->assign('page',$show);// 赋值分页输出

    	$user_sql="select face,nikename,answer_num,id from user  order by answer_num desc limit 6";
		$mongood=M()->query($user_sql);
		$this->assign('mongood',$mongood);//月度雷锋

		$hot_card_sql="select title,view_num,id from question order by view_num desc limit 10";
		$hotcard_res=M()->query($hot_card_sql);
		$this->assign('hotcard',$hotcard_res); //最近热帖

		$hot_answer_sql="select title,answer_num,id from question order by answer_num desc limit 10";
		$hotanswer_res=M()->query($hot_answer_sql);
		$this->assign('hotanswer',$hotanswer_res); //最近热议

    	$this->display('index');

    	
    }
    //已采纳
    public function haveget(){
    	 $sql="select t1.*,t2.nikename,t2.id,t2.face,t3.cname from question t1 inner join user t2 on t1.uid=t2.id inner join category t3 on t1.cid=t3.id where t1.status='已采纳' order by t1.create_time desc" ;

    	$res=M()->query($sql);
    	$this->assign('res',$res);


    	$user_sql="select face,nikename,answer_num,id from user  order by answer_num desc limit 6";
		$mongood=M()->query($user_sql);
		$this->assign('mongood',$mongood);//月度雷锋

		$hot_card_sql="select title,view_num,id from question order by view_num desc limit 10";
		$hotcard_res=M()->query($hot_card_sql);
		$this->assign('hotcard',$hotcard_res); //最近热帖

		$hot_answer_sql="select title,answer_num,id from question order by answer_num desc limit 10";
		$hotanswer_res=M()->query($hot_answer_sql);
		$this->assign('hotanswer',$hotanswer_res); //最近热议


    	$this->display('index');
    }
    //精致帖
    public function fineget(){
    	 $this->display('index');
    }














}